//
//  SNHStaticTableViewSectionInfo.m
//  Pods
//
//  Created by 陈建蕾 on 2018/6/9.
//

#import "SNHStaticTableViewSectionInfo.h"
#import "SNHStaticTableViewCellInfo.h"

@interface SNHStaticTableViewSectionInfo ()
@property (nonatomic, strong) NSMutableArray *arrays;
@end

@implementation SNHStaticTableViewSectionInfo

- (instancetype)init {
    if (self = [super init]) {
        [self _config];
    }
    return self;
}

- (void)_config {
    _footerHeight = 0.01f;
    _headerHeight = 0.01f;
}

+ (instancetype)defaultSectionInfo {
    return [SNHStaticTableViewSectionInfo new];
}

+ (instancetype)headerSectionInfoWithTitle:(NSString *)title {
    SNHStaticTableViewSectionInfo *sectionInfo = [self defaultSectionInfo];
    [sectionInfo setUserInfoValue:title forKey:@"headerTitle"];
    sectionInfo.headerHeight = -1.0;
    return sectionInfo;
}

+ (instancetype)headerSectionWithView:(UIView *)view {
    SNHStaticTableViewSectionInfo *sectionInfo = [self defaultSectionInfo];
    [sectionInfo setUserInfoValue:view forKey:@"headerView"];
    sectionInfo.headerHeight = view.frame.size.height;
    return sectionInfo;
}

+ (instancetype)footerSectionWithTitle:(NSString *)title {
    SNHStaticTableViewSectionInfo *sectionInfo = [self defaultSectionInfo];
    [sectionInfo setUserInfoValue:title forKey:@"footerTitle"];
    sectionInfo.footerHeight = -1.0;
    return sectionInfo;
}

+ (instancetype)footerSectionWithView:(UIView *)view {
    SNHStaticTableViewSectionInfo *sectionInfo = [self defaultSectionInfo];
    [sectionInfo setUserInfoValue:view forKey:@"footerView"];
    sectionInfo.headerHeight = view.frame.size.height;
    return sectionInfo;
}

+ (instancetype)sectionInfoWithHeader:(NSString *)headerTitle footer:(NSString *)footerTitle {
    SNHStaticTableViewSectionInfo *sectionInfo = [self defaultSectionInfo];
    [sectionInfo setUserInfoValue:headerTitle forKey:@"headerTitle"];
    [sectionInfo setUserInfoValue:footerTitle forKey:@"footerTitle"];
    sectionInfo.headerHeight = -1.0;
    sectionInfo.footerHeight = -1.0;
    return sectionInfo;
}

- (void)addCellInfo:(SNHStaticTableViewCellInfo *)cell {
    [self.arrays addObject:cell];
}

- (void)insertCellInfo:(SNHStaticTableViewCellInfo *)cell atIndex:(NSInteger)index {
    [self.arrays insertObject:cell atIndex:index];
}

- (void)removeCellAtIndex:(NSInteger)index {
    if (index >= self.arrays.count) return;
    [self.arrays removeObjectAtIndex:index];
}

- (SNHStaticTableViewCellInfo *)getCellInfoAtIndex:(NSInteger)index {
    if (index >= self.arrays.count) return nil;
    return self.arrays[index];
}

- (NSInteger)rowCount {
    return self.arrays.count;
}

#pragma mark - Private
- (NSMutableArray *)arrays {
    if (!_arrays) {
        _arrays = [NSMutableArray array];
    }
    return _arrays;
}
@end
